HttpWatch Automation Reference - 16.2.2
Using HttpWatch Automation with Ruby / Ruby - Recording with HttpWatch
In This Topic
    Ruby - Recording with HttpWatch
    In This Topic

    First, your application needs to create or attach to an instance of the browser that uses HttpWatch, as explained in the Ruby - Overview. Having done this, your application will contain references to Controller and Plugin objects.

    The following discussion assumes that these object references are called control and plugin, respectively.

    Filter Control

    Before starting recording, you should decide whether to enable or disable HttpWatch filtering. The automation interface only allows you to enable or disable an existing filter. The filtering criteria itself can only be set up manually through the HttpWatch extension user interface.

    If you do not specifically want to use a filter it is best to disable filtering in your application, as follows:

     

    Turn Off Filtering
    Copy Code
    plugin.Log.EnableFilter(false)
    

     

    Alternatively, to enable filtering, make the same call, but with the parameter set to  true.

    Clearing the HttpWatch Log and the Browser Cache

    To make sure that you don't pick up traffic that was previously recorded in HttpWatch by a user or another automation program, you should clear the Log object that is associated with the Plugin. This can be done with the Plugin object's Clear method:

     

    Clear the HttpWatch Log
    Copy Code
    plugin.Clear()
    

     

    It may also be necessary to put the browser into a known state at the start of your test. Often this is achieved by clearing the browser cache and cookie database to emulate the state of the browser when a new visitor opens a web page. The extension object provides two methods, ClearCache and ClearAllCookies to perform these tasks.

    Starting Recording

    To activate traffic logging, call the Plugin object's Record method:

     

    Start Recording
    Copy Code
    plugin.Record()
    

    Generating HTTP Traffic to Record

    Of course, nothing will be recorded by HttpWatch until the browser starts to access and interact with web pages.

    In an automation program, there are two ways to drive the browser:

    1. Use a framework that has been designed to drive browser interactions, e.g. Selenium
    2. Use the Plugin object's GotoURL method

    Option 2 is less powerful and flexible than the first option, but it provides a simple way to test that pages load correctly and to measure their performance.

    The GotoURL method returns immediately without waiting for the page to load. Normally, you would want to wait for the page to load so that you could look at the traffic that it generated or the performance timings gathered by HttpWatch. To do this, call the Controller object's Wait method, passing the Plugin object reference and a timeout value in seconds (-1 waits forever):

     

    Loading a Page using HttpWatch
    Copy Code
    myUrl = 'http://www.example.com/'
    plugin.GotoURL(myUrl)
    control.Wait( plugin, -1 ) # don't return until the page loads
    

     

    For more information about how the page load is detected please see the documentation for the IsLoadingPage property and the Wait method.

    The GotoURL method is somewhat limited and only allows you to load pages. If you require more complex interaction with a web page you may want to consider using the Selenium framework with Ruby.

    Stopping Recording

    When you wish to stop recording HTTP traffic, call the Plugin object's Stop method:

    Stop Recording
    Copy Code
    plugin.Stop()
    

    Closing the Browser

    At the end of your application, or earlier if appropriate, you should close the browser by calling the Plugin object's CloseBrowser method:

    Close the Browser
    Copy Code
    plugin.CloseBrowser()
    

     

    See Also